<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/icon.css" />
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css" />
<script type="text/javascript" src="js/common.js"></script>
<title>发货单</title>
</head>
<body>
	<style type="text/css">
.step {
	margin-top: 15px;
}
</style>
	<script type="text/javascript">
		function deleteSgf(sgfId){
			$.messager.confirm('提示','确定要删除吗？',function(v){
				if(v){
					$.getJSON('deleteSgf',{
						sgfId:sgfId
					},function(obj){
						if(obj.success){
							$("#zj-sgf-all-dg").datagrid('reload');
						}else{
							$.messager.alert('提示','操作失败,原因'+ obj.message);
						}
					});
				}
			});
			
		}
		
		$(function() {
			$("#zj-sgf-all-dg")
					.datagrid(
							{
								url : 'getAllSgf',
								fit : true,
								border : false,
								toolbar : '#zj-sgf-tb',
								pageSize : 9,
								pageList : '[5,8,9,10,15,20]',
								fitColumns : true,
								method : 'get',
								singleSelect : false,
								pagination : true,
								columns : [ [
										{
											field : 'sgf',
											width : 1,
											checkbox : true
										},
										{
											field : 'sgfId',
											title : 'ID',
											width : 1,
										},
										{
											field : 'cusVoName',
											title : '客户',
											width : 2,
										},
										{
											field : 'orderVoTheme',
											title : '订单',
											width : 2,
										},
										{
											field : 'sgfSendMan',
											title : '发货人',
											width : 1,
										},
										{
											field : 'sgfTime',
											title : '发货日期',
											width : 2,
											formatter : function(value, row,
													index) {
												if (value) {
													var date = new Date(value);
													var y = date.getFullYear();
													var m = date.getMonth() + 1;
													var d = date.getDate();
													return y + '-' + m + '-'
															+ d;
												}
											}
										},
										{
											field : 'sgfWay',
											title : '发货方式',
											width : 2
										},
										{
											field : 'sgfCoTheme',
											title : '状态',
											width : 1
										},
										{
											field : 'sgfcaozuo',
											title : '操作',
											width : 4,
											formatter : function(value, row,
													index) {
												var che_btn = '<a class="zj-sgf-che-btn" onclick="cheSgf('
														+ row.sgfId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var fa_goods_btn = '<a class="zj-sgf-fa-goods-btn" onclick="faGoodsSgf('
														+ row.sgfId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var editSgf = '<a class="zj-sgf-edit" onclick="editSgf('
														+ row.sgfId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var deleteSgf = '<a class="zj-sgf-delete" onclick="deleteSgf('
														+ row.sgfId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												if (row.sgfCoTheme == '已发货') {
													return che_btn + editSgf
															+ deleteSgf;
												} else if (row.sgfCoTheme == '已出库') {
													return fa_goods_btn
															+ che_btn + editSgf
															+ deleteSgf;
												} else {
													return editSgf + deleteSgf;
												}
											}
										} ] ],
								onLoadSuccess : function(data) {
									$('.zj-sgf-che-btn').linkbutton({
										text : '撤销',
										plain : true,
										iconCls : 'icon-ok'
									});
									$('.zj-sgf-fa-goods-btn').linkbutton({
										text : '发货',
										plain : true,
										iconCls : 'icon-reload'
									});
									$('.zj-sgf-edit').linkbutton({
										text : '编辑',
										plain : true,
										iconCls : 'icon-edit'
									});
									$('.zj-sgf-delete').linkbutton({
										text : '删除',
										plain : true,
										iconCls : 'icon-cancel'
									});
								},
								rowStyler : function(index, row) {
									return 'height:30px';
								}
							});
			$("#zj_sgf_list_all").linkbutton({
				onClick : function() {
					$("#zj-sgf-all-dg").datagrid({
						pageNumber : 1,
						url : 'getAllSgf'
					});
					$("#zj-sgf-all-dg").datagrid('reload');
				}
			});
		});
	</script>
	<div id="zj-sgf-tb">
		<a id="zj_btn_sgf_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加</a><a
			id="zj_sgf_list_all" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	<table id="zj-sgf-all-dg"></table>
	
	<div id="zj-sgf-add-dg" class="easyui-dialog" title="新建发货单"
		style="width: 450px; height: 420px;"
		data-options="iconCls:'icon-save',closed:true,resizable:true,modal:true,buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
					$('#zj-sgf-add-form').form({
						onSubmit:function(param){
							return $(this).form('validate');
						},
						success:function(v){
						var obj = eval('('+v+')');
							if(obj.success){
								$('#zj-sgf-all-dg').datagrid('reload');
							}else{
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
							}
							$('#zj-sgf-add-dg').dialog('close');
						}	
					}).submit();
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#zj-sgf-add-dg').dialog('close');
				}
			}]">
		<form id="zj-sgf-add-form" method="post" action="addSgf">
			<div class="step">
				<input id="zj-sgd-form-cus" name="custId" class="easyui-textbox"
					data-options="buttonText:'选择客户',required:true,labelAlign:'right',label:' ',labelWidth:'90',width:320, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-sgd-form-cus').textbox('setValue', row.custId);
							$('#zj-sgd-form-cus').textbox('setText', row.custName);
						});		
					}">
			</div>
			<div class="step">
				<input id="zj-input-sgd-order" class="easyui-combobox"
					data-options="panelHeight:'auto',required:true,labelAlign:'right',label:'订单',
					width:270, labelWidth:90"
					name="coId">
			</div>
			<div class="step">
				<input id="zj-input-sgd-order-pro" class="easyui-combobox"
					data-options="panelHeight:'auto',labelAlign:'right',required:true,label:'产品',
					width:250, labelWidth:90"
					name="sgdProId">
			</div>
			<div class="step">
				<input class="easyui-numberbox" name="sgdProPrice"
					data-options="min:0,precision:2,labelAlign:'right',required:true,label:'单价',
							width:220, labelWidth:90">
			</div>

			<div class="step">
				<input class="easyui-numberbox" name="sgdCost"
					data-options="min:0,precision:2,labelAlign:'right',required:false,label:'单个成本',
							width:200, labelWidth:90">
			</div>
			<div class="step">
				<input class="easyui-numberbox" name="sgdNumber"
					data-options="min:0,precision:0,labelAlign:'right',required:true,label:'交付数量',
							width:200, labelWidth:90">
			</div>
			<div class="step">
				<input class="easyui-datebox"
					data-options="required:true,labelAlign:'right',label:'交付日期',
					width:300, labelWidth:90"
					name="sgdTime">
			</div>
			<div class="step">
				<input id="zj-input-order-pro" class="easyui-textbox"
					data-options="labelAlign:'right',label:'对方接收人',
					width:250, labelWidth:90"
					name="sgdRemarks">
			</div>
		</form>
	</div>
</body>
</html>